﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MethodWorx.CMS.Content;
using MethodWorx.CMS.UI.Models.Shared;
using System.Web.Mvc;
using MethodWorx.CMS.UI.Application;
using MethodWorx.CMS.Services;

namespace MethodWorx.CMS.UI.Models
{
    public class ConfigurePageTemplateModel
    {
        private SchemaService service;
        public PageTemplateBasicDetails PageTemplateBasicDetails { get; set; }

        public ConfigurePageTemplateModel(SchemaService service, Guid id)
        {
            this.service = service;
            var pt = this.service.GetPageTemplateById(id);
            if (pt == null)
                throw new WebException("Page Template Not Found");

            this.PageTemplateBasicDetails = new PageTemplateBasicDetails()
            {
                Name = pt.Name,
                Description = pt.Description,
                ParentsSelectList = this.GetParentsSelectList(pt),
                Id = pt.Id
            };
        }



        public SelectList GetParentsSelectList(PageTemplate pageTemplate)
        {
            return new SelectList(service.GetAbstractPageTemplates().Where(pt => pt.Id != pageTemplate.Id), "Id", "Name", ((pageTemplate.Parent == null) ? Guid.Empty : pageTemplate.Parent.Id));
        }
    }
}